<template>
      <swiper :options="swiperOption">
        <swiper-slide  v-for="(page,index) in pagescpmputed" :key="index">
          <div class="icons">
            <div class="iconitem" v-for="item in page" :key="item.id">
              <img class="iconitemimg" :src="item.imgUrl" alt="">
              <span class="iconitemtext">{{item.desc}}</span>
            </div>
          </div>
        </swiper-slide>
      </swiper>
</template>

<script>
export default {
  name: 'homeicons',
  props: {
    list: Array
  },
  data () {
    return {
      swiperOption: {
        autoplay: false
      }
    }
  },
  computed: {
    pagescpmputed: function () {
      const pages = []
      this.list.forEach((item, index) => {
        // 计算页码
        const page = Math.floor(index / 8)
        // 如果pages的下标page不存在，则pages[page] = [];
        if (!pages[page]) {
          pages[page] = []
        }
        pages[page].push(item)
      })
      return pages
    }
  }
}
</script>

<style scoped>
  .icons{
    width: 100%;
    display: flex;
    flex-direction: row;
    flex-wrap: wrap;
  }
  .iconitem{
    width: 25%;
    height: 50%;
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    padding-top: 10px;
  }
  .iconitemimg{
    width: 56%;
  }
  .iconitemtext{
    width: 100%;
    text-align: center;
    margin: 4px 0;
    overflow: hidden;
    white-space: nowrap;
    text-overflow: ellipsis;
  }
</style>
